package com.project.chat.pojo;

import com.project.chat.common.CH;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChiHuiTool {

    private static final Map<Integer, ChiHui> CHI_HUI_LIST = new HashMap<>();
    private static int chiHuiID = 0; //创建词汇编号
    private static ChiHuiTool chiHuiTool;

    public static ChiHuiTool createChiHuiTool(){
        if(chiHuiTool == null) {
            chiHuiTool = new ChiHuiTool();
            //默认放入八组词汇
            addChiHui(new ChiHui(CH.CH_1.p, CH.CH_1.w));
            addChiHui(new ChiHui(CH.CH_2.p, CH.CH_2.w));
            addChiHui(new ChiHui(CH.CH_3.p, CH.CH_3.w));
            addChiHui(new ChiHui(CH.CH_4.p, CH.CH_4.w));
            addChiHui(new ChiHui(CH.CH_5.p, CH.CH_5.w));
            addChiHui(new ChiHui(CH.CH_6.p, CH.CH_6.w));
            addChiHui(new ChiHui(CH.CH_7.p, CH.CH_7.w));
            addChiHui(new ChiHui(CH.CH_8.p, CH.CH_8.w));

            return chiHuiTool;
        }

        return chiHuiTool;
    }

    private ChiHuiTool(){}

    //增加词汇
    public static void addChiHui(ChiHui chiHui){
        if(chiHui != null){
            chiHui.setId(chiHuiID);
            CHI_HUI_LIST.put(chiHuiID++, chiHui);
        }
    }

    //删除词汇
    public void deleteChiHui(int id){
        CHI_HUI_LIST.remove(id);
    }

    //查询所有词汇
    public List<ChiHui> getChiHuis(){
          return new ArrayList<>(CHI_HUI_LIST.values());
    }

    //查询某一词汇
    public ChiHui getChiHui(int id){
        return CHI_HUI_LIST.get(id);
    }
}
